package cn.walls1717.wallsmall.order.pojo.vo;

import cn.walls1717.wallsmall.order.pojo.po.MemberReceiveAddressDO;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认
 *
 * @author walls1717
 * @since 2022/11/18 11:38
 **/
public class OrderConfirmVO implements Serializable {

    /** 收货地址 */
    @Setter
    @Getter
    private List<MemberReceiveAddressDO> address;
    /** 订单项 */
    @Setter
    @Getter
    private List<OrderItemVO> items;
    // TODO 发票
    /** 优惠券 */
    @Setter
    @Getter
    private Integer integration;
    /** 应付价格 */
    private BigDecimal payPrice;
    /** 防重复令牌 */
    @Setter
    @Getter
    private String orderToken;
    /** 库存信息 */
    @Setter
    @Getter
    private Map<Long, Boolean> stocks;

    /**
     * 订单总额
     */
    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (items != null) {
            for (OrderItemVO item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    /** 获取总件数 */
    public Integer getCount() {
        Integer i = 0;
        if (items != null) {
            for (OrderItemVO item : items) {
                i = item.getCount();
            }
        }
        return i;
    }

    public BigDecimal getPayPrice() {
        return getTotal();
    }
}
